//
//  RootViewController.m
//  UI16_图片加载
//
//  Created by dllo on 15/11/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "UIImageView+WebCache.h"
#import "NetWorkHandle.h"

@interface RootViewController ()

@property (nonatomic, retain) UIImageView *imageV;

@end

@implementation RootViewController

- (void)dealloc
{
    [_imageV release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(50, 100, 300, 200)];
    self.imageV.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.imageV];
    [_imageV release];
    // 点击按钮加载图片
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(50, 500, 80, 50);
    button.backgroundColor = [UIColor greenColor];
    [button setTitle:@"加载图片" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
//    NSString *urlStr = @"http://img4.duitang.com/uploads/item/201207/28/20120728105310_jvAjW.thumb.600_0.jpeg";
//
//    NSURL *url = [NSURL URLWithString:urlStr];
//    
//    // sd_webImage方法
////    [imageV sd_setImageWithURL:url];
//    
//    [self.imageV  sd_setImageWithURLStr:urlStr];
//
//    [self.imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"image2.jpg"]];
    
    
}

- (void)buttonAction
{
    NSString *urlStr = @"http://img4.duitang.com/uploads/item/201207/28/20120728105310_jvAjW.thumb.600_0.jpeg";
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    // sd_webImage方法
        [self.imageV sd_setImageWithURL:url];
    
//        [self.imageV  sd_setImageWithURLStr:urlStr];
    
//    [self.imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"image2.jpg"]];
    
//    void(^netDataBlock)(NSData *) = ^(NSData *netData){
//    
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:netData options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"%@", dic);
//    };
//    
//    [NetWorkHandle getDataUnSyWithUTRLStr:@"http://api.map.baidu.com/place/v2/search?query=银行&region=大连&output=json&ak=6E823f587c95f0148c19993539b99295" block:netDataBlock];
    
    
//    [NetWorkHandle getDataUnSyWithUTRLStr:@"http://api.map.baidu.com/place/v2/search?query=银行&region=大连&output=json&ak=6E823f587c95f0148c19993539b99295" block:^(NSData *netData) {
//        
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:netData options:NSJSONReadingMutableContainers error:nil];
//        NSLog(@"%@", dic);
    
    
//    }];
    
    [[SDWebImageManager sharedManager].imageCache calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
        
        NSLog(@"缓存文件大小:%ld, 总大小:%ld", fileCount, totalSize);
        
    }];
    
//    //失败后重试
//    SDWebImageRetryFailed = 1 << 0,
//    
//    //UI交互期间开始下载，导致延迟下载比如UIScrollView减速。
//    SDWebImageLowPriority = 1 << 1,
//    
//    //只进行内存缓存
//    SDWebImageCacheMemoryOnly = 1 << 2,
//    
//    //这个标志可以渐进式下载,显示的图像是逐步在下载
//    SDWebImageProgressiveDownload = 1 << 3,
//    
//    //刷新缓存
//    SDWebImageRefreshCached = 1 << 4,
//    
//    //后台下载
//    SDWebImageContinueInBackground = 1 << 5,
//    
//    //NSMutableURLRequest.HTTPShouldHandleCookies = YES;
//    
//    SDWebImageHandleCookies = 1 << 6,
//    
//    //允许使用无效的SSL证书
//    //SDWebImageAllowInvalidSSLCertificates = 1 << 7,
//    
//    //优先下载
//    SDWebImageHighPriority = 1 << 8,
//    
//    //延迟占位符
//    SDWebImageDelayPlaceholder = 1 << 9,
//    
//    //改变动画形象
//    SDWebImageTransformAnimatedImage = 1 << 10,
    
//    // 清除内存缓存
//    [[SDWebImageManager sharedManager].imageCache clearMemory];
//    
//    // 清除磁盘缓存
//    [[SDWebImageManager sharedManager].imageCache clearDisk];
//    
//    // iOS7之后,还需要增加清掉系统缓存
//    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
